﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Models;
using DAL;
using WebShopAPI.Models;
namespace WebShopAPI.Controllers
{
    public class ddxsController : ApiController
    {
        sp_orderServcie n = new sp_orderServcie();
        sp_order_goodsDAL nn = new sp_order_goodsDAL();
        sp_consigneeDAL nnn = new sp_consigneeDAL();
        sp_ProductServcie sp = new sp_ProductServcie();
        sp_goods_picsService p = new sp_goods_picsService();
        public ResponData get(int id,int sl)
        {
            int gs = sl * 3;
            List<sp_order> ii = n.GetAll().Where(p => p.user_id == id).ToList();
            List<sp_order> dd= ii.OrderByDescending(p => p.order_id).Take(gs).ToList();
            List<fhdx> kk = new List<fhdx>();
            for (int i = 0; i < dd.Count; i++)
            {
                fhdx jj = new fhdx();
                jj.dd = dd[i];
                List<sp_order_goods> k= dd[i].sp_order_goods.ToList();
                List<goodsym> j = new List<goodsym>();
                for (int q = 0; q< k.Count; q++)
                {
                    goodsym s = new goodsym();
                    s.list = sp.cx().Where(p => p.Id == k[q].goods_id).FirstOrDefault();
                    s.number = k[q].goods_number;
                    s.pic = p.GetAll().Where(p => p.goods_id == s.list.Goods_id).ToList()[0].pics_mid;
                    j.Add(s);
                }
                jj.spjh = j;
                kk.Add(jj);
            }
            ResponData d = new ResponData();
            d.data = kk;
            d.meta.msg = "订单查询成功";
            d.meta.status = 200;
            return d;
        }
    }
    public class fhdx {
        public sp_order dd { get; set; }
        public List<goodsym> spjh { get; set; }
    }
 

}
